/*
 * SimuladorView.java
 */

package simulador;

/**Manipulación de archivos*/
import java.io.File;


/**Componentes de interfaz gráfica*/
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
 * Frame principal de la aplicación
 */
public class SimuladorView extends FrameView {
    /**Venatana de configuración de la simulación*/
    private Configuracion configuracion;
    /**Archivos de los hilos*/
    private File[] archivosHilos;
    /**Computadora que ejecutará la simulación*/
    private Computadora computadora;
    /**Quantum del protocolo round-robin para la asignación del CPU*/
    private int quantum;
    /**Número de ciclos que tarda un acceso a memoria*/
    private int tiempoAccesoMemoria;
    /**Quantum por defecto. Si el usuario no ingresa un quantum, se usa
     este valor*/
    private final int QUANTUM_DEFECTO;
    /**Tiempo de acceso a memoria por defecto. Si el usuario no ingresa
     un quantum, se usa este valor*/
    private final int TIEMPO_ACCESO_MEMORIA_DEFECTO;

    //private javax.swing.JTextField[][] cache1;
    //private javax.swing.JPanel panel1;

public SimuladorView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
               // statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
       // statusAnimationLabel.setIcon(idleIcon);
       // progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                       // statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                  //  progressBar.setVisible(true);
                  //  progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
               //     statusAnimationLabel.setIcon(idleIcon);
                //    progressBar.setVisible(false);
              //      progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                //    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
            ///        progressBar.setVisible(true);
              //      progressBar.setIndeterminate(false);
               //     progressBar.setValue(value);
                }
            }
        });
        this.QUANTUM_DEFECTO = 5;
        this.TIEMPO_ACCESO_MEMORIA_DEFECTO = 6;
        this.archivosHilos = null;
        this.quantum = this.QUANTUM_DEFECTO;
        this.tiempoAccesoMemoria = this.TIEMPO_ACCESO_MEMORIA_DEFECTO;
        this.configuracion = new Configuracion(this);
        int reg[] = new int[32];
        for(int i = 0; i < 32; i++){
            reg[i] = (int)(Math.random() * 100);
        }
        this.actualizarRegistrosNucleo1(reg);
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = SimuladorApp.getApplication().getMainFrame();
            aboutBox = new SimuladorAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        SimuladorApp.getApplication().show(aboutBox);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        textoIDHilo1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        textoInstruccion1 = new javax.swing.JTextField();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaCache1 = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        textoIDHilo2 = new javax.swing.JTextField();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaCache2 = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        textoInstruccion2 = new javax.swing.JTextField();
        label1 = new java.awt.Label();
        textoReloj = new javax.swing.JFormattedTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tablaRegistros1 = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tablaRegistros2 = new javax.swing.JTable();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        jFileChooser1 = new javax.swing.JFileChooser();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(simulador.SimuladorApp.class).getContext().getResourceMap(SimuladorView.class);
        mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
        mainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        mainPanel.setForeground(resourceMap.getColor("mainPanel.foreground")); // NOI18N
        mainPanel.setMaximumSize(new java.awt.Dimension(500, 350));
        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(500, 350));

        jPanel1.setBackground(resourceMap.getColor("PanelProcesador.background")); // NOI18N
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("PanelProcesador.border.title"))); // NOI18N
        jPanel1.setName("PanelProcesador"); // NOI18N

        jPanel2.setBackground(resourceMap.getColor("PanelNucleoUno.background")); // NOI18N
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("PanelNucleoUno.border.title"))); // NOI18N
        jPanel2.setName("PanelNucleoUno"); // NOI18N

        textoIDHilo1.setEditable(false);
        textoIDHilo1.setText(resourceMap.getString("tbIDhilo1.text")); // NOI18N
        textoIDHilo1.setName("tbIDhilo1"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        textoInstruccion1.setEditable(false);
        textoInstruccion1.setText(resourceMap.getString("textoInstruccion1.text")); // NOI18N
        textoInstruccion1.setName("textoInstruccion1"); // NOI18N

        jLayeredPane3.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jLayeredPane3.border.title"))); // NOI18N
        jLayeredPane3.setName("jLayeredPane3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tablaCache1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Palabra0", null, null, null, null},
                {"Palabra1", null, null, null, null},
                {"Palabra2", null, null, null, null},
                {"Palabra3", null, null, null, null},
                {"Palabra4", null, null, null, null},
                {"Palabra5", null, null, null, null},
                {"Palabra6", null, null, null, null},
                {"Palabra7", null, null, null, null}
            },
            new String [] {
                "", "Bloque0", "Bloque1", "Bloque2", "Bloque3"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaCache1.setFocusable(false);
        tablaCache1.setName("tablaCache1"); // NOI18N
        tablaCache1.setRowSelectionAllowed(false);
        jScrollPane1.setViewportView(tablaCache1);

        jScrollPane1.setBounds(10, 20, 260, 160);
        jLayeredPane3.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLayeredPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(textoInstruccion1)
                            .addComponent(textoIDHilo1, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(textoIDHilo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoInstruccion1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel3.border.title"))); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(461, 468));

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        textoIDHilo2.setEditable(false);
        textoIDHilo2.setText(resourceMap.getString("tbIDhilo2.text")); // NOI18N
        textoIDHilo2.setName("tbIDhilo2"); // NOI18N

        jLayeredPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jLayeredPane2.border.title"))); // NOI18N
        jLayeredPane2.setName("jLayeredPane2"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tablaCache2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Palabra0", null, null, null, null},
                {"Palabra1", null, null, null, null},
                {"Palabra2", null, null, null, null},
                {"Palabra3", null, null, null, null},
                {"Palabra4", null, null, null, null},
                {"Palabra5", null, null, null, null},
                {"Palabra6", null, null, null, null},
                {"Palabra7", null, null, null, null}
            },
            new String [] {
                "", "Bloque0", "Bloque1", "Bloque2", "Bloque3"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tablaCache2.setFocusable(false);
        tablaCache2.setName("tablaCache2"); // NOI18N
        tablaCache2.setRowSelectionAllowed(false);
        jScrollPane2.setViewportView(tablaCache2);

        jScrollPane2.setBounds(10, 20, 270, 160);
        jLayeredPane2.add(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        textoInstruccion2.setEditable(false);
        textoInstruccion2.setName("textoInstruccion2"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(82, 82, 82)
                                .addComponent(textoIDHilo2, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textoInstruccion2))))
                    .addComponent(jLayeredPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(textoIDHilo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoInstruccion2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        label1.setName("label1"); // NOI18N
        label1.setText(resourceMap.getString("label1.text")); // NOI18N

        textoReloj.setEditable(false);
        textoReloj.setText(resourceMap.getString("tbReloj.text")); // NOI18N
        textoReloj.setName("tbReloj"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textoReloj, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(139, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoReloj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, 0, 285, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jButton1.setText(resourceMap.getString("btIniciar.text")); // NOI18N
        jButton1.setName("btIniciar"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        tablaRegistros1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaRegistros1.setEnabled(false);
        tablaRegistros1.setFocusable(false);
        tablaRegistros1.setMinimumSize(new java.awt.Dimension(100, 16));
        tablaRegistros1.setName("tablaRegistros1"); // NOI18N
        tablaRegistros1.setRowSelectionAllowed(false);
        jScrollPane3.setViewportView(tablaRegistros1);

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        tablaRegistros2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaRegistros2.setEnabled(false);
        tablaRegistros2.setFocusable(false);
        tablaRegistros2.setName("tablaRegistros2"); // NOI18N
        tablaRegistros2.setRowSelectionAllowed(false);
        jScrollPane4.setViewportView(tablaRegistros2);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jButton1))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel5))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel6))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 810, Short.MAX_VALUE)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 810, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText(resourceMap.getString("abrirMenuItem.text")); // NOI18N
        jMenuItem1.setName("abrirMenuItem"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem1);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(simulador.SimuladorApp.class).getContext().getActionMap(SimuladorView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        menuBar.add(jMenu1);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        jFileChooser1.setName("jFileChooser1"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        this.jFileChooser1.setMultiSelectionEnabled(true);
        this.jFileChooser1.showOpenDialog(menuBar);
        this.archivosHilos = this.jFileChooser1.getSelectedFiles();
        if(this.archivosHilos.length < 2){//Para que tenga sentido tener 2
            //núcleos, deben haber al menos 2 hilos
            javax.swing.JOptionPane.showMessageDialog(this.getComponent(),
                                                      "Deben haber al menos 2 hilos",
                                                      "Error",
                                                      javax.swing.JOptionPane.ERROR_MESSAGE);
            this.archivosHilos = null;
        }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        this.configuracion.setVisible(true);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(this.archivosHilos == null){//si el usuario no ha indicado los hilos
            //Mostrar mensaje de error
            javax.swing.JOptionPane.showMessageDialog(this.getComponent(),
                                    "Debe indicar los archivos de los hilos(File->Abrir)",
                                    "Error",
                                    javax.swing.JOptionPane.ERROR_MESSAGE);
        }
        else{
            this.jButton1.setEnabled(false);
            //instanciar al objeto Computadora
            this.computadora = new Computadora(this,
                                               this.archivosHilos,
                                               this.quantum,
                                               this.tiempoAccesoMemoria);
            //iniciar simulación
            new Thread(computadora, "hiloComputadora").start();
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    /**Asigna quantum
     * @param q quantum
     */
    public void setQuantum(int q){
        this.quantum = q;
    }
    /**Asigna tiempo de acceso a memoria
     * @param t tiempo de acceso a memoria
     */
    public void setTiempoAccesoMemoria(int t){
        this.tiempoAccesoMemoria = t;
    }
    /**Obtiene el quantum
     * @return quantum
     */
    public int getQuantum(){
        return this.quantum;
    }
    /**Obtiene el tiempo de acceso a memoria
     * @return tiempo de acceso a memoria
     */
    public int getTiempoAccesoMemoria(){
        return this.tiempoAccesoMemoria;
    }
    /**Actualiza la caché
     * del núcleo 1 mostrada en pantalla.
     * @param matriz matriz de enteros con el contenido con el que se actualizará
     * la caché del núcleo 1 mostrada en pantalla.
     * @throws ArrayIndexOutOfBoundsException - si <code>matriz</code> tiene
     * menos filas (o columnas) que las filas (o columnas respectivamente)
     * de de la caché del núcleo 1
     */
    public void actualizarCacheNucleo1(int[][] matriz) throws ArrayIndexOutOfBoundsException{
        this.actualizarCache(matriz, tablaCache1);
    }
    /**Actualiza la caché
     * del núcleo 2 mostrada en pantalla.
     * @param matriz matriz de enteros con el contenido con el que se actualizará
     * la caché del núcleo 2 mostrada en pantalla.
     * @throws ArrayIndexOutOfBoundsException - si <code>matriz</code> tiene
     * menos filas (o columnas) que las filas (o columnas respectivamente)
     * de de la caché del núcleo 2
     */
    public void actualizarCacheNucleo2(int[][] matriz) throws ArrayIndexOutOfBoundsException{
        this.actualizarCache(matriz, tablaCache2);
    }
    /**Actualiza el contenido de <code>tabla</code> de modo que coincida con el de
     * <code>matriz</code>
     * @param matriz matriz con el contenido que se copiará a <code>tabla</code>
     * @param tabla tabla cuyo contenido se refrescará de modo que coincida con
     * <code>matriz</code>
     * @throws ArrayIndexOutOfBoundsException si el número de filas (o columnas)
     * de la matriz <code>matriz</code> es menor que el número de filas 
     * (o columnas, respectivamente) de <code>tabla</code>
     */
    private void actualizarCache(int[][] matriz, javax.swing.JTable tabla) throws ArrayIndexOutOfBoundsException{
        for(int fil = 0; fil < tabla.getModel().getRowCount(); fil++){
            for(int col = 0; col < tabla.getModel().getColumnCount() - 1; col++){
                tabla.getModel().setValueAt(matriz[fil][col], fil, col+1);
            }
        }
    }
    /**Actualiza el contenido de los registros del núcleo 1 mostrados en pantalla
     * @param regs arreglo con el contenido con el que se actualizarán los registros
     * del núcleo 1 mostrados en pantalla.
     * @throws ArrayIndexOutOfBoundsException si el tamaño del arreglo
     * <code>regs</code> es menor que la cantidad de registros del núcleo 1
     */
    public void actualizarRegistrosNucleo1(int[] regs)throws ArrayIndexOutOfBoundsException{
        this.actualizarRegistros(regs, this.tablaRegistros1);
    }
    /**Actualiza el contenido de los registros del núcleo 2 mostrados en pantalla
     * @param regs arreglo con el contenido con el que se actualizarán los registros
     * del núcleo 2 mostrados en pantalla.
     * @throws ArrayIndexOutOfBoundsException si el tamaño del arreglo
     * <code>regs</code> es menor que la cantidad de registros del núcleo 2
     */
    public void actualizarRegistrosNucleo2(int[] regs)throws ArrayIndexOutOfBoundsException{
        this.actualizarRegistros(regs, this.tablaRegistros2);
    }
    /**Actualiza el contenido de <code>tabla</code> de modo que coincida con el de
     * <code>regs</code>
     * @param regs arreglo con el contenido que se copiará a <code>tabla</code>
     * @param tabla tabla cuyo contenido se refrescará de modo que coincida con
     * <code>regs</code>
     * @throws ArrayIndexOutOfBoundsException si el tamaño del arreglo
     * <code>regs</code> es menor que la cantidad de columnas de <code>tabla</code>
     */
    private void actualizarRegistros(int[] regs, javax.swing.JTable tabla)throws ArrayIndexOutOfBoundsException{
        for(int i = 0; i < tabla.getModel().getColumnCount(); i++){
            tabla.getModel().setValueAt(regs[i], 0, i);
        }
    }
    /**Actualiza el contenido de la instrucción saliente en el núcleo 1 mostrado
     * en pantalla, de modo que coincida con <code>id</code>
     * @param id valor con el que se actualizará el contenido de la instrucción
     * saliente en el núcleo 1 mostrado en pantalla.
     */
    public void actualizarInstruccionSalienteNucleo1(String id){
        this.textoInstruccion1.setText(id);
    }
    /**Actualiza el contenido de la instrucción saliente en el núcleo 2 mostrado
     * en pantalla, de modo que coincida con <code>id</code>
     * @param id valor con el que se actualizará el contenido de la instrucción
     * saliente en el núcleo 2 mostrado en pantalla.
     */
    public void actualizarInstruccionSalienteNucleo2(String id){
        this.textoInstruccion2.setText(id);
    }
    /**Actulaiza el contenido del id del hilo del núcleo 1 mostrado en pantalla,
     * de modo que coincida con <code>id</code>
     * @param id valor con el que se actualizará el contenido del id del hilo
     * del núcleo 1 mostrado en pantalla.
     */
    public void actualizarIDHiloNucleo1(String id){
        this.textoIDHilo1.setText(id);
    }
    /**Actulaiza el contenido del id del hilo del núcleo 2 mostrado en pantalla,
     * de modo que coincida con <code>id</code>
     * @param id valor con el que se actualizará el contenido del id del hilo
     * del núcleo 2 mostrado en pantalla.
     */
    public void actualizarIDHiloNucleo2(String id){
        this.textoIDHilo2.setText(id);
    }
    /**Actulaiza el reloj de la máquina mostrado en pantalla,
     * de modo que coincida con <code>r</code>
     * @param r valor con el que se actualizará el reloj de la máquina
     */
    public void actualizarReloj(String r){
        this.textoReloj.setText(r);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private java.awt.Label label1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTable tablaCache1;
    private javax.swing.JTable tablaCache2;
    private javax.swing.JTable tablaRegistros1;
    private javax.swing.JTable tablaRegistros2;
    private javax.swing.JTextField textoIDHilo1;
    private javax.swing.JTextField textoIDHilo2;
    private javax.swing.JTextField textoInstruccion1;
    private javax.swing.JTextField textoInstruccion2;
    private javax.swing.JFormattedTextField textoReloj;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
